import detail from '../promotion_details/promotion_details.vue'
import defaultImg from '@/components/defaultImg/defaultImg'
import timLogin from '@/utils/timLogin.js'
export default {
  components: {
    defaultImg
  },
  data() {
    return {
      showPage: false,
      AccountType: 0, //权限
      current: 0,
      //推广列表
      OrderList: {
        0: [],
        1: [],
        2: [],
        3: [],
        4: [],
        5: []
        // 6: []
      },
      listTabs: [{
        name: '全部'
      },
      {
        name: '进行中'
      },
      {
        name: '待传发票',
      },
      {
        name: '待审核',
      },
      /* {
        name: '待结算',
      }, */
      {
        name: '已结算',
      },
      {
        name: '已失效',
      },
      ],
      pageIndex: [1, 1, 1, 1, 1, 1],
      status: ['loadmore', 'loadmore', 'loadmore', 'loadmore', 'loadmore', 'loadmore'], //默认状态
      imsotplist: []
    }
  },
  onLoad(op) {
    if (op.tabId) {
      console.log(op.tabId, '传过来的id')
      this.current = Number(op.tabId)
    }
  },

  created() {
    this.getMyInfo()
    this.getShareOrderPageList()
  },
  methods: {
    //加载更多
    more() {
      this.getShareOrderPageList()
    },
    onPullDownRefresh() {
      this.OrderList[this.current] = []
      this.pageIndex[this.current] = 1
      this.getShareOrderPageList()
    },
    onReachBottom() {
      if (this.status[this.current] !== 'nomore') {
        this.getShareOrderPageList()
      }

    },
    //个人信息
    async getMyInfo() {
      uni.showLoading({
        title: '加载中'
      })
      try {
        const res = await this.$api.me.getMyInfo()
        this.AccountType = res.data.account_Type
        uni.hideLoading()
      } catch (err) {
        uni.hideLoading()
      }
    },
    //个人详情
    goPage(list) {
      uni.navigateTo({
        url: '/pages_userModule/memberDetails/memberDetails?from=chat&id=' + list.userId
      })
    },
    toDetailPage(list, status, storeId) {
      let color = list.color
      console.log(list.orderId)
      if (this.AccountType === 2) {
        uni.navigateTo({
          url: '/pages_order/promotionDetailsFacilitator/promotionDetailsFacilitator?id=' + list.orderId + '&userId=' +
						list.userId
        })
      } else {
        uni.navigateTo({
          url: '/pages_order/promotion_details/promotion_details?id=' + list.orderId + '&userId=' + list.userId
        })
      }
    },
    //加载数据状态
    moreStatus(status) {
      this.status[this.current] = status
    },
    //tab切换
    change(i) {
      this.current = i
      if (this.OrderList[i].length === 0) {
        this.getShareOrderPageList()
      }
    },
    loading() {
      uni.hideLoading()
    },
    //推广订单数据
    async getShareOrderPageList() {
      this.moreStatus('loading')
      let tabsChange = this.current
      if(this.current===4){
        tabsChange = 5
      }else if(this.current===5){
        tabsChange = 6
      }
      uni.showLoading({
        title: '加载中',
        mask: true
      })
      try {
        let data = {
          'pageIndex': this.pageIndex[this.current],
          'pageSize': 10,
          'selectType': tabsChange
        }
        const res = await this.$api.order.getShareOrderPageList(data)
        this.OrderList[this.current] = [...this.OrderList[this.current], ...res.data.list]
        this.$u.debounce(this.loading, 1000)
        let length = res.data.list.length
        uni.stopPullDownRefresh()
        this.showPage = true
        if (res.data.total <= 10) {
          this.status[this.current] = 'nomore'
        } else {
          this.moreStatus(length !== 0 ? 'loadmore' : 'nomore')
        }
        // this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
        if (length === 0) return false
        this.pageIndex[this.current] += 1 // 当前页加1

      } catch (e) {
        this.showPage = false
        this.$u.debounce(this.loading, 1000)
        uni.stopPullDownRefresh()
      }
    },
    getCont(types){
      // console.log(types)
      this.$store.commit('news/createConversationActive', {
			  user: types.storeName, //店铺名称
			  img: types.storeImg, //店铺头像
			  lastTime: '', //
			  userId: types.storeId, //店铺id
			  conversationID: 'C2C',
      })
      this.$store.commit('news/setCardInfo', {
        imgSrc: types.storeImg,
        name: types.carName,
        price: types.factory_money,
        type: 'resaleCar',
        goPage: '3',
        payment: types.down_payment_money,//首付
        monthly: types.installment_monthly_money//月供
      })
      console.log(types)
      uni.navigateTo({
			  url: '/pages_common/contactSeller/contactSeller?user=' + types.storeName + '&pageId=' + types.orderId+ '&tab=1&show=3' + '&userId=' + types.userId
      })
      /* uni.navigateTo({
			  url: '/pages_common/room/room?user=' + types.storeName  // + '&pageId=' + types.storeId
      }) */
    },
    imclick(types) {
      if (this.$store.state.isSDKReady) {
			  this.getCont(types)
      } else {
			  timLogin(() => {
			    this.getCont(types)
			  })
      }

    }
  }
}
